package com.xinyue.ext.reader.core;

import org.dom4j.Element;

import com.xinyue.ext.exception.ManyException;
import com.xinyue.ext.reader.ParamHolder;
import com.xinyue.ext.reader.dao.JoinProcess;
import com.xinyue.ext.util.ListWrapper;

public class DaoManyReader {
	//参数集
	private static ParamHolder holder;
	
	//私有构造器
	private DaoManyReader() {
	}
	//内部类
	private static class SingletonHolder{
        private static DaoManyReader instance = new DaoManyReader();  
    }
	/**
	 * 获得对象实例
	 */
	public static DaoManyReader getInstance(ParamHolder holder) {
		DaoManyReader.holder = holder;
		//dao对象的import文件路径集合
		DaoManyReader.holder.setDaoImpt(new ListWrapper());
		DaoManyReader.holder.setDaoImptExt(new ListWrapper());
		return SingletonHolder.instance;
	}

	/**
	 * 读取many-many标签数据并封装dao数据
	 * @throws ManyException 
	 */
	public void read(Element many) throws ManyException {
		JoinProcess.getInstance(holder).joinRead(many);
		
		//set import
		holder.getEntity().getDao().setImports(holder.getDaoImpt().getList());
		holder.getEntity().getDao().setImportExt(holder.getDaoImptExt().getList());
	}
}
